const CryptoJS = require('crypto-js');

function MD() {
    "use strict";
    function r(e) {
        v = new Array(e);
        for (var t = 0; t < v.length; t++)
            v[t] = 0;
        y = new b,
        (P = new b).digits[0] = 1
    }
    function b(e) {
        this.digits = "boolean" == typeof e && 1 == e ? null : v.slice(0),
        this.isNeg = !1
    }
    function w(e) {
        var t = new b(!0);
        return t.digits = e.digits.slice(0),
        t.isNeg = e.isNeg,
        t
    }
    function o(e) {
        var t, n = new b;
        for (n.isNeg = e < 0,
        e = Math.abs(e),
        t = 0; 0 < e; )
            n.digits[t++] = e & z,
            e >>= L;
        return n
    }
    function f(e) {
        for (var t = "", n = e.length - 1; -1 < n; --n)
            t += e.charAt(n);
        return t
    }
    function i(e) {
        return 48 <= e && e <= 57 ? e - 48 : 65 <= e && e <= 90 ? 10 + e - 65 : 97 <= e && e <= 122 ? 10 + e - 97 : 0
    }
    function a(e) {
        for (var t = new b, n = e.length, r = 0; 0 < n; n -= 4,
        ++r)
            t.digits[r] = function(e) {
                for (var t = 0, n = Math.min(e.length, 4), r = 0; r < n; ++r)
                    t <<= 4,
                    t |= i(e.charCodeAt(r));
                return t
            }(e.substr(Math.max(n - 4, 0), Math.min(n, 4)));
        return t
    }
    function E(e, t) {
        var n, r, o, i;
        if (e.isNeg != t.isNeg)
            t.isNeg = !t.isNeg,
            n = x(e, t),
            t.isNeg = !t.isNeg;
        else {
            for (n = new b,
            i = r = 0; i < e.digits.length; ++i)
                o = e.digits[i] + t.digits[i] + r,
                n.digits[i] = 65535 & o,
                r = Number(R <= o);
            n.isNeg = e.isNeg
        }
        return n
    }
    function x(e, t) {
        var n, r, o, i;
        if (e.isNeg != t.isNeg)
            t.isNeg = !t.isNeg,
            n = E(e, t),
            t.isNeg = !t.isNeg;
        else {
            for (n = new b,
            i = o = 0; i < e.digits.length; ++i)
                r = e.digits[i] - t.digits[i] + o,
                n.digits[i] = 65535 & r,
                n.digits[i] < 0 && (n.digits[i] += R),
                o = 0 - Number(r < 0);
            if (-1 == o) {
                for (i = o = 0; i < e.digits.length; ++i)
                    r = 0 - n.digits[i] + o,
                    n.digits[i] = 65535 & r,
                    n.digits[i] < 0 && (n.digits[i] += R),
                    o = 0 - Number(r < 0);
                n.isNeg = !e.isNeg
            } else
                n.isNeg = e.isNeg
        }
        return n
    }
    function _(e) {
        for (var t = e.digits.length - 1; 0 < t && 0 == e.digits[t]; )
            --t;
        return t
    }
    function k(e) {
        for (var t = _(e), n = e.digits[t], r = (t + 1) * D, o = r; r - D < o && 0 == (32768 & n); --o)
            n <<= 1;
        return o
    }
    function u(e, t) {
        for (var n, r, o, i, a = new b, u = _(e), l = _(t), c = 0; c <= l; ++c) {
            for (o = c,
            i = n = 0; i <= u; ++i,
            ++o)
                r = a.digits[o] + e.digits[i] * t.digits[c] + n,
                a.digits[o] = r & z,
                n = r >>> L;
            a.digits[c + u + 1] = n
        }
        return a.isNeg = e.isNeg != t.isNeg,
        a
    }
    function S(e, t) {
        for (var n, r = new b, o = _(e), i = 0, a = 0; a <= o; ++a)
            n = r.digits[a] + e.digits[a] * t + i,
            r.digits[a] = n & z,
            i = n >>> L;
        return r.digits[1 + o] = i,
        r
    }
    function l(e, t, n, r, o) {
        for (var i = Math.min(t + o, e.length), a = t, u = r; a < i; ++a,
        ++u)
            n[u] = e[a]
    }
    function C(e, t) {
        var n, r, o, i, a = Math.floor(t / D), u = new b;
        for (l(e.digits, 0, u.digits, a, u.digits.length - a),
        r = D - (n = t % D),
        i = (o = u.digits.length - 1) - 1; 0 < o; --o,
        --i)
            u.digits[o] = u.digits[o] << n & z | (u.digits[i] & A[n]) >>> r;
        return u.digits[0] = u.digits[o] << n & z,
        u.isNeg = e.isNeg,
        u
    }
    function O(e, t) {
        var n, r, o, i, a = Math.floor(t / D), u = new b;
        for (l(e.digits, a, u.digits, 0, e.digits.length - a),
        r = D - (n = t % D),
        i = (o = 0) + 1; o < u.digits.length - 1; ++o,
        ++i)
            u.digits[o] = u.digits[o] >>> n | (u.digits[i] & I[n]) << r;
        return u.digits[u.digits.length - 1] >>>= n,
        u.isNeg = e.isNeg,
        u
    }
    function T(e, t) {
        var n = new b;
        return l(e.digits, 0, n.digits, t, n.digits.length - t),
        n
    }
    function c(e, t) {
        var n = new b;
        return l(e.digits, t, n.digits, 0, n.digits.length - t),
        n
    }
    function s(e, t) {
        var n = new b;
        return l(e.digits, 0, n.digits, 0, t),
        n
    }
    function N(e, t) {
        if (e.isNeg != t.isNeg)
            return 1 - 2 * Number(e.isNeg);
        for (var n = e.digits.length - 1; 0 <= n; --n)
            if (e.digits[n] != t.digits[n])
                return e.isNeg ? 1 - 2 * Number(e.digits[n] > t.digits[n]) : 1 - 2 * Number(e.digits[n] < t.digits[n]);
        return 0
    }
    function d(e, t) {
        var n, r, o, i, a, u, l, c, s, f, d, p, h, m, g = k(e), v = k(t), y = t.isNeg;
        if (g < v)
            return e.isNeg ? ((n = w(P)).isNeg = !t.isNeg,
            e.isNeg = !1,
            t.isNeg = !1,
            r = x(t, e),
            e.isNeg = !0,
            t.isNeg = y) : (n = new b,
            r = w(e)),
            new Array(n,r);
        for (n = new b,
        r = e,
        o = Math.ceil(v / D) - 1,
        i = 0; t.digits[o] < F; )
            t = C(t, 1),
            ++i,
            ++v,
            o = Math.ceil(v / D) - 1;
        for (r = C(r, i),
        g += i,
        u = T(t, (a = Math.ceil(g / D) - 1) - o); -1 != N(r, u); )
            ++n.digits[a - o],
            r = x(r, u);
        for (l = a; o < l; --l) {
            for (c = l >= r.digits.length ? 0 : r.digits[l],
            s = l - 1 >= r.digits.length ? 0 : r.digits[l - 1],
            f = l - 2 >= r.digits.length ? 0 : r.digits[l - 2],
            d = o >= t.digits.length ? 0 : t.digits[o],
            p = o - 1 >= t.digits.length ? 0 : t.digits[o - 1],
            n.digits[l - o - 1] = c == d ? z : Math.floor((c * R + s) / d),
            h = n.digits[l - o - 1] * (d * R + p),
            m = c * B + (s * R + f); m < h; )
                --n.digits[l - o - 1],
                h = n.digits[l - o - 1] * (d * R | p),
                m = c * R * R + (s * R + f);
            (r = x(r, S(u = T(t, l - o - 1), n.digits[l - o - 1]))).isNeg && (r = E(r, u),
            --n.digits[l - o - 1])
        }
        return r = O(r, i),
        n.isNeg = e.isNeg != y,
        e.isNeg && (n = (y ? E : x)(n, P),
        r = x(t = O(t, i), r)),
        0 == r.digits[0] && 0 == _(r) && (r.isNeg = !1),
        new Array(n,r)
    }
    function p(e) {
        this.modulus = w(e),
        this.k = _(this.modulus) + 1;
        var t = new b;
        t.digits[2 * this.k] = 1,
        this.mu = (e = this.modulus,
        d(t, e)[0]),
        this.bkplus1 = new b,
        this.bkplus1.digits[this.k + 1] = 1,
        this.modulo = h,
        this.multiplyMod = m,
        this.powMod = g
    }
    function h(e) {
        for (var t = c(e, this.k - 1), t = c(u(t, this.mu), this.k + 1), n = x(s(e, this.k + 1), s(u(t, this.modulus), this.k + 1)), r = 0 <= N(n = n.isNeg ? E(n, this.bkplus1) : n, this.modulus); r; )
            r = 0 <= N(n = x(n, this.modulus), this.modulus);
        return n
    }
    function m(e, t) {
        t = u(e, t);
        return this.modulo(t)
    }
    function g(e, t) {
        var n, r, o = new b;
        for (o.digits[0] = 1,
        n = e,
        r = t; 0 != (1 & r.digits[0]) && (o = this.multiplyMod(o, n)),
        0 != (r = O(r, 1)).digits[0] || 0 != _(r); )
            n = this.multiplyMod(n, n);
        return o
    }
    var v, y, P, M, j, A, I, L = 16, D = L, R = 65536, F = R >>> 1, B = R * R, z = R - 1;
    r(20),
    o(1e15),
    M = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"),
    j = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"),
    A = new Array(0,32768,49152,57344,61440,63488,64512,65024,65280,65408,65472,65504,65520,65528,65532,65534,65535),
    I = new Array(0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535),
    this.RSAKeyPair = function(e, t, n) {
        this.e = a(e),
        this.d = a(t),
        this.m = a(n),
        this.chunkSize = 2 * _(this.m),
        this.radix = 16,
        this.barrett = new p(this.m)
    },
    this.setMaxDigits = r,
    this.encryptedString = function(e, t) {
        for (var n, r, o, i, a, u, l = new Array, c = t.length, s = 0; s < c; )
            l[s] = t.charCodeAt(s),
            s++;
        for (; 0 != l.length % e.chunkSize; )
            l[s++] = 0;
        for (n = l.length,
        r = "",
        s = 0; s < n; s += e.chunkSize) {
            for (a = new b,
            o = 0,
            i = s; i < s + e.chunkSize; ++o)
                a.digits[o] = l[i++],
                a.digits[o] += l[i++] << 8;
            u = e.barrett.powMod(a, e.e),
            r += (16 == e.radix ? function(e) {
                var t, n = "";
                for (_(e),
                t = _(e); -1 < t; --t)
                    n += function(e) {
                        var t, n = "";
                        for (t = 0; t < 4; ++t)
                            n += j[15 & e],
                            e >>>= 4;
                        return f(n)
                    }(e.digits[t]);
                return n
            }(u) : function(e, t) {
                var n, r, o = new b;
                for (o.digits[0] = t,
                n = d(e, o),
                r = M[n[1].digits[0]]; 1 == N(n[0], y); )
                    n = d(n[0], o),
                    digit = n[1].digits[0],
                    r += M[n[1].digits[0]];
                return (e.isNeg ? "-" : "") + f(r)
            }(u, e.radix)) + " "
        }
        return r.substring(0, r.length - 1)
    }
}
function asrsea(e, t, n, r) {
    var o = {},
        i = function(e) {
        for (var t, n = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", r = "", o = 0; o < e; o += 1)
            t = Math.random() * n.length,
            t = Math.floor(t),
            r += n.charAt(t);
        return r
    }(16);
    return o.encText = a(e, r),
    o.encText = a(o.encText, i),
    o.encSecKey = u(i, t, n),
    o
}
function a(e, t) {
    var n = CryptoJS.enc.Utf8.parse(t),
        t = CryptoJS.enc.Utf8.parse("0102030405060708"),
        e = CryptoJS.enc.Utf8.parse(e);
    return CryptoJS.AES.encrypt(e, n, {
        iv: t,
        mode: CryptoJS.mode.CBC
    }).toString();
}
function u(e, t, n) {
    var ww = module.exports = new MD;
    return ww.setMaxDigits(131),
        n = new ww.RSAKeyPair(t,"",n),
        ww.encryptedString(n, e);
}
var encpwd = CryptoJS.MD5('qazwsx123').toString();
var e = ['https://music.163.com/api/login/cellphone'];
var e2 = {
    "countrycode": 86,
    "phone": "13535353535",
    "password": encpwd,
    "rememberLogin": "true",
    "secureCaptcha": "CN31_GrUMueqXQEHDXvD2wefbDJLiybvMtB58FomdQ0AFDx.I-bYgslP1Opmkzkkk5oAa7DSZklUxxFJXVH8lJZM9eh0_y.x.i2uAsCmXBjuX2ofSZajieRMi5jyOmOzZIs2Ae6HWyKzwCEwUzNRLUaw5PONfcfw_sLX1hgof7Zr8zvgJQpnatfD9ZTH9K0vQqd9_kb1rQSqUzAlLVt_fd90JBGVSoCaCB1SiA2W1E8A-NI2KvpwU7mtGuBkacK5w0wtNjKQ9oEqwhhVspGU-SpGHLWBQ6hRUcmMcaZDOO4j7mG.zFhVFe4nXHB8B9Q02GhVSY2AyragtpEx1z2kXOVGqUvWjK9FltZhVOcvXKasDkikbMrAZc6gHcxGZpzCCCEdUCZ1a62UeNxtA6uKGXAEGFrTZxDbkx5jFt9bqCUyCmTz6nUnai2XKcC_sZJh.V0BXMJqFH8fbq_vmlEa1TdFJnwHL.-WNsQVgAwl_oLLUlwRx6WQac8z_Z4wZRsm3",
    "checkToken": "9ca17ae2e6ffcda170e2e6ee8bee7fb39babb2f93b83bc8bb7c44b879e9bb0c841ba95ae87ec638bb5febbb52af0feaec3b92af5e8b68fea7eabe99a83f75f939b9ab6d14aa69eab8bcf48ad8fbb9ae16b81b7ee9e"
};
var s = e2;
var p = asrsea(JSON.stringify(s), '010001', '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7', '0CoJUm6Qyw8W8jud');
console.log(p.encText.length,p.encSecKey.length);
// o.body = obj2query({
//     params: p.encText,
//     encSecKey: p.encSecKey
// })

